﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.ComponentModel;


namespace WpfUMLTry1.ViewModel
{
    class CharSelect_VM : VM_Base
    {
        private Int32 loadingSlot;
        #region VM variables
        public Boolean loadGameButton1Enable { get { return loadGameButtonEnable(1); } }
        public Boolean loadGameButton2Enable { get { return loadGameButtonEnable(2); } }
        public Boolean loadGameButton3Enable { get { return loadGameButtonEnable(3); } }

        public DelegateCommand loadCharacter { get; set; }
        public DelegateCommand createCharacter { get; set; }
        #endregion

        public CharSelect_VM()
        {
            //loadCharacter = new DelegateCommand(param => View.Switcher.Switch(new View.CreateChar(), new ViewModel.CreateChar_VM(Convert.ToInt32(param))));

            loadCharacter = new DelegateCommand(param => { loadingSlot = Convert.ToInt32(param); loadCharacterFnc(); });
            createCharacter = new DelegateCommand(param => newCharacter(Convert.ToInt32(param)));
        }

        private void newCharacter(Int32 slotN)
        {
            View.Switcher.Switch(new View.CreateChar(), new ViewModel.CreateChar_VM(Convert.ToInt32(slotN)));
        }

        private void loadCharacterFnc()
        {
            Model.gameModel gMod = null;
            try
            {
                gMod = Data.GameDataManager.LoadGame(loadingSlot);
            }
            catch (Data.FileIOExc e)
            {
                newCharacter(loadingSlot);
            }
            View.Switcher.Switch(new View.InTheTown(gMod));
        }

        private Boolean loadGameButtonEnable(Int32 slotNumber)
        {
            String fName = "saveG" + slotNumber.ToString() + ".rpg";
            return Data.GameDataManager.fileExsists(fName);
        }
    }
}
